from wxauto import WeChat
import pandas as pd
from time import sleep
title = "第二周习题反馈"

# 读取需要通知的名单
titanic_data = pd.read_csv('通知\\'+title+'.csv')


# 通知内容
notice = ''
with open('通知\\'+title+'.txt', "r") as f:  # 打开文件
    notice = f.read()  # 读取文件


# 初始化微信
wx = WeChat()

def send_Msg(name,msg):
    
    wx.ChatWith(name)
    wx.SendMsg(msg, who=name)

# 遍历生成通知名单
for i in range(len(titanic_data['姓名'])):
    if(titanic_data['发送状态'][i]!=1):
        tmp = notice.replace('`1`',titanic_data['姓名'][i])
        tmp = tmp.replace('`2`',titanic_data['家长'][i])
        tmp = tmp.replace('`3`',titanic_data['习题次数'][i])
        if(titanic_data['错误题目'][i]=='全部正确'):
            tmp = tmp.replace('`4`','本次习题'+titanic_data['姓名'][i]+'全部正确，下次继续努力！')
        elif(titanic_data['错误题目'][i]=='请假'):
            tmp = tmp.replace('`4`',titanic_data['习题次数'][i]+'课，'+titanic_data['姓名'][i]+'请假了，后面上课可以把习题带过来我批改')
        elif(titanic_data['错误题目'][i]=='没交'):
            tmp = tmp.replace('`4`','这次习题老师没收到'+titanic_data['姓名'][i]+'的，后面上课可以把习题带过来我批改')
        else:
            tmp = tmp.replace('`4`','错误题目：'+titanic_data['错误题目'][i]+'\n纠错方法：'+titanic_data['纠错方法'][i])
        tmp += '\n家长有任何问题都可以及时和我沟通哈！'
        print(tmp)
        send_Msg(name=titanic_data['姓名'][i]+titanic_data['家长'][i],msg=tmp)
    
